class Solution(object):
    def totalHammingDistance(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        total = 0
        for t in range(31):
            count_0 = 0
            count_1 = 0
            for num in nums:
                if (num >> t) & 1:
                    count_1 += 1
                else:
                    count_0 += 1
            total += count_0 * count_1
        return total


data = Solution()
nums = [4, 14, 2]
print(data.totalHammingDistance(nums))